package com.site.dao;

import com.site.common.DbHelper;
import com.site.entity.NewTypeEntity;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewTypeDao extends DbHelper {
    public NewTypeDao() throws ClassNotFoundException, SQLException {
    }

    //得到新闻类型
    public List<NewTypeEntity> getAll() throws SQLException {
        ResultSet rs= query("select * from tbnewtype");
        List<NewTypeEntity> list=new ArrayList<NewTypeEntity>();
        while (rs.next()){
            list.add(getEntity(rs));
        }

        rs.close();
        close();
        return list;
    }

    private NewTypeEntity getEntity(ResultSet rs) throws SQLException {
        NewTypeEntity entity=new NewTypeEntity();
        entity.setTitle(rs.getString("title"));
        entity.setTitleEn(rs.getString("titleEn"));
        return entity;
    }
}
